/*
 * Copyright 2012 Lexaden.com
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package com.navajo.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.web.context.WebApplicationContext;

import com.google.common.eventbus.EventBus;
import com.navajo.web.business.ApplicationUI;
import com.navajo.web.business.page.MainPage;
import com.navajo.web.business.page.SideBarMenu;
import com.navajo.web.business.view.navigation.NavigationView;
import com.navajo.web.spring.DefaultMessageSource;
import com.navajo.web.spring.MessageSource;
import com.vaadin.navigator.Navigator;

@Configuration
public class ApplicationContext {
	
    @Bean(name="APPLICATION")
    @Scope(WebApplicationContext.SCOPE_SESSION)
    public ApplicationUI applicationUI() {
        return new ApplicationUI();
    }
    
    
    
   
    
    
    
    
    

    @Bean
    @Scope(WebApplicationContext.SCOPE_SESSION)
    public EventBus eventBus()
    {
    	return new EventBus();
    }
    
    
    @Bean
    @Scope(WebApplicationContext.SCOPE_SESSION)
    public MainPage mainPage()
    {
    	MainPage bean=new MainPage();
    	eventBus().register(bean);
    	return bean;
    }
    
    
    @Bean
    @Scope(WebApplicationContext.SCOPE_SESSION)
    public NavigationView navigationView()
    {
        NavigationView bean=new NavigationView();
        eventBus().register(bean);
        return bean;
    }
    
    
    @Bean
    @Scope(WebApplicationContext.SCOPE_SESSION)
    public SideBarMenu sideBarMenu()
    {
        SideBarMenu bean=new SideBarMenu();
        eventBus().register(bean);
        return bean;
    }
    
    
    
    
    
    @Bean
    public MessageSource messageSource()
    {
    	DefaultMessageSource bean=new DefaultMessageSource();
        bean.setBasename("messages");
        bean.setUseCodeAsDefaultMessage(true);
        
        return bean;
    }

    
    
    
//    @Bean
//    public CustomScopeConfigurer customScopeConfigurer() {
//        final CustomScopeConfigurer customScopeConfigurer = new CustomScopeConfigurer();
//        final Map<String, Object> hashMap = new HashMap<String, Object>();
//        hashMap.put(ApplicationScope.NAME, new ApplicationScope());
//        customScopeConfigurer.setScopes(hashMap);
//        return customScopeConfigurer;
//    }


    
    
    
  
}